<template>
  <div class="app-container">
    <h2>问题：{{message.publishContent}}</h2>
    <h2>回复：</h2>
    <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%">
      <el-table-column prop="messageId" label="Id" width="100" />
      <el-table-column label="状态" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 0">用户</span>
          <span v-else-if="scope.row.status === 1">老师</span>
          <span v-else-if="scope.row.status === 2">AI</span>
        </template>
      </el-table-column>
      <el-table-column prop="userName" label="用户" width="100" />
      <el-table-column prop="publishContent" label="内容" show-overflow-tooltip />
      <el-table-column prop="likes" label="点赞数" width="70" />
      <el-table-column prop="createTime" label="创建时间" width="160px" />
    </el-table>
  </div>
</template>

<script>
  import messageApi from '@/api/message'

  export default {
    data() {
      return {
        id: null,
        listLoading: true,
        tableData: [],
        message:{}
      };
    },
    created() {
      this.id = this.$route.query.id;
      // console.log(this.id)
      this.search()
    },
    watch: {
      // 监听$route对象的变化来更新查询参数
      '$route': function(to, from) {
        this.id = to.query.id;
        this.search()
      }
    },
    methods: {
      search() {
        messageApi.findByPid(this.id).then(data => {
          this.message=data.response.message
          this.tableData = data.response.children
          this.listLoading = false
        })
      }
    }
  }
</script>

<style>
</style>
